package org.codeart.status.example02;

/**
 * 交通灯类
 */
public class TrafficLight {

    // 初始化状态
    private String state = "red";
    
    // 切换为绿灯 通行状态
    public void switchToGreen() {
        if ("green".equals(state)) {
            System.out.println("当前为绿灯, 无需切换!");
        } else if ("red".equals(state)) {
            state = "green";
            System.out.println("绿灯亮起... 时长: 60s");
        } else if ("yellow".equals(state)) {
            state = "green";
            System.out.println("绿灯亮起... 时长: 15s");
        }
    }

    public void switchToYellow() {
        if ("green".equals(state)) {
            state = "yellow";
            System.out.println("黄灯亮起... 时长: 3s");
        } else if ("red".equals(state)) {
            System.out.println("当前是红灯, 不能切换为黄灯");
        } else if ("yellow".equals(state)) {
            System.out.println("当前是黄灯, 无需切换");
        }
    }

    public void switchToRed() {
        if ("green".equals(state)) {
            System.out.println("当前是绿灯, 不能切换为红灯");
        } else if ("red".equals(state)) {
            System.out.println("当前是红灯, 无需切换");
        } else if ("yellow".equals(state)) {
            state = "red";
            System.out.println("红灯亮起... 时长: 90s");
        }
    }
}
